import 'package:flutter/material.dart';
import 'package:flutter_axrjc/routes.dart';
import 'package:flutter_axrjc/style.dart';
import 'package:flutter_axrjc/widget/common_widget.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';

class ReportMonthPage extends StatelessWidget {
  const ReportMonthPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<ReportMonthLogic>();
    final state = Get.find<ReportMonthLogic>().state;

    return Scaffold(
      backgroundColor: const Color(0xffEFEFEF),
      appBar: AppBar(
        leading:
            InkWell(onTap: Get.back, child: const Icon(Icons.arrow_back_ios)),
        title: const Text("月度报告"),
        centerTitle: true,
      ),
      body: SmartRefresher(
        header: reFreshHeader(),
        footer: loadFooter(),
        enablePullUp: true,
        enablePullDown: true,
        onLoading: () {
          logic.getList(isRefresh: false);
        },
        onRefresh: () {
          logic.getList(isRefresh: true);
        },
        controller: logic.refreshController,
        child: Obx(() {
          if (state.list.isEmpty) {
            return const Center(
              child: Text("没有检测记录"),
            );
          }
          return ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            padding: const EdgeInsets.symmetric(vertical: 10),
            itemCount: state.list.length,
            itemBuilder: (BuildContext context, int index) {
              var bean = state.list[index];
              return InkWell(
                onTap: () {
                  Get.toNamed(MainRoutes.reportMonthDetail, arguments: bean);
                },
                child: Padding(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                  child: Container(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(10)),
                    child: Column(
                      children: [
                        Padding(
                          padding: const EdgeInsets.symmetric(vertical: 5),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "${bean.fixtureName}",
                                style: const TextStyle(fontSize: 16),
                              ),
                              const Text(
                                "查看报告",
                                style: TextStyle(color: orangeColor),
                              ),
                            ],
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.symmetric(vertical: 5),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  const Text("照度度数"),
                                  Text(
                                    "${bean.detectionAverageValue}",
                                    style: const TextStyle(color: primaryColor),
                                  ),
                                ],
                              ),
                              Row(
                                children: [
                                  const Text(
                                    "检测时间",
                                    style: TextStyle(color: Color(0xffdcdcdc)),
                                  ),
                                  Text(
                                    "${bean.detectionStartTime}",
                                    style: const TextStyle(
                                        color: Color(0xffdcdcdc)),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        }),
      ),
    );
  }
}
